package com.example.zzl.view.fragment.ShareOrderFragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.zzl.R;
import com.example.zzl.view.fragment.ShareOrderFragment.adapter.InforAdapter;
import com.example.zzl.view.fragment.ShareOrderFragment.disan.JsonAsyncTask;
import com.example.zzl.view.fragment.ShareOrderFragment.fragment.MyListView;
import com.example.zzl.view.fragment.ShareOrderFragment.model.Infor;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import jp.wasabeef.glide.transformations.CropCircleTransformation;


/**
 * Created by Administrator on 2017/2/11.
 */

public class ShareInformation extends AppCompatActivity {
    private List<Infor>list;
    private List<Object> objects;
    private TextView tv1,tv2;
    private ImageView iv;
    private MyListView lv;
    private View footView;
    private  int yemianid,shangpinid;
    private InforAdapter adapter;
    private Toolbar toolbar;
    private String url="http://mws.biyabi.com/WebService.asmx/GetShareShoppingInfoBySSIDToRead?UserID=0&SSID=";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.shareinfo);
        Intent intent=getIntent();
         yemianid = intent.getIntExtra("yemianid",0);
        shangpinid=intent.getIntExtra("shangpinid",0);
        toolbar=(Toolbar)findViewById(R.id.too);

        setSupportActionBar(toolbar);

        init();
        loadData();
    }

    private void loadData() {
        new JsonAsyncTask(this, new JsonAsyncTask.CallBack() {
            @Override
            public void sendData(String json) {
                Type type=new TypeToken<ArrayList<Infor>>(){}.getType();
                list=new Gson().fromJson(json,type);

                adapter=new InforAdapter(getBaseContext(),list);
                lv.setAdapter(adapter);
                objects.addAll(list);
                adapter.notifyDataSetChanged();
                tv1.setText(list.get(0).getNickName());
                tv2.setText(list.get(0).getInfoTime());
                Glide.with(ShareInformation.this).load(list.get(0).HeadImage).bitmapTransform(new CropCircleTransformation(ShareInformation.this)).into(iv);



            }
        }).execute(url+yemianid);
    }


    private void init() {
        tv1=(TextView)findViewById(R.id.nickname);
        tv2=(TextView)findViewById(R.id.tv2);
        iv=(ImageView)findViewById(R.id.infomation_img);
        lv=(MyListView) findViewById(R.id.info_lv);
        objects=new ArrayList<>();

        toolbar.setNavigationIcon(R.drawable.btn_back_grey);


        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        lv.setAdapter(adapter);
    }
}
